package org.peoples.utils {
	
	import mx.core.UIComponent;
	import com.qualityattributes.errors.UnsupportedOperationError;
	
	public class ContentManager {
		
		private static var instance:ContentManager;
		private static var init:Boolean = false;
		
		private var _container:UIComponent;
		
		public function ContentManager() {
			if (!init)
				throw new UnsupportedOperationError("ContentManager must be instantiated by using ContentManager.getInstance()");
		}
		
		public static function getInstance():ContentManager {
			init = true;
			
			if (instance == null)
				instance = new ContentManager();
				
			return instance;
		}
		
		private function removeContent():void {
			var len:int = container.numChildren;
			for (var i:int = 0; i < len; i++) {
				container.removeChildAt(i);
			}
		}
		
		public function swapContent(content:UIComponent):void {
			removeContent();
			container.addChild(content);
		}
		
		public function get container():UIComponent {
			return this._container;
		}
		public function set container(value:UIComponent):void {
			this._container = value;
		}
		
	}
	
}